package com.yfq.springframework.support;

import com.yfq.springframework.BeanFactory;
import com.yfq.springframework.beans.config.BeanDefinition;

/**
 * @author 姚凤桥
 * @date 2022/11/22 16:02
 * @description
 */
public abstract class AbstractBeanFactory extends DefaultSingletonBeanRegistry implements BeanFactory {
    @Override
    public Object getBean(String beanName) {
        return getBean(beanName, null);
    }

    @Override
    public Object getBean(String beanName, Object... args) {
        Object bean = getSingletonBean(beanName);
        if (bean != null) {
            return bean;
        }

        BeanDefinition beanDefinition = getBeanDefinition(beanName);
        return createBean(beanName, beanDefinition, args);
    }

    protected abstract BeanDefinition getBeanDefinition(String beanName);

    protected abstract Object createBean(String beanName, BeanDefinition beanDefinition, Object... args);
}
